package com.wings4.accounting

import com.wings4.security.User

class AccountHead {

   String accountHeadName;
   String headShortName;
   AccountHead accountParentHead;        //...........It's would be payment type  ..............//
   String accountHeadCode
   AccountType accountType //------------It will be Replace By Account Type-----------------------//
   Byte accountStatus;
   Date statusDate;
   Boolean isPosted;
   BigDecimal openingBalance;
   Module module;
   Branch branch;
   User user;
   Date headCreatedDate;


    static constraints = {
        headShortName(nullable: true);
        accountParentHead(nullable: true);
        accountHeadCode(nullable: true);
        accountType(nullable: true);
        accountStatus(nullable: true);
        statusDate(nullable: true);
        isPosted(nullable: true);
        openingBalance(nullable: true);
        module(nullable: true);
        branch(nullable: true);
        user(nullable: true);
        headCreatedDate(nullable: true);
        accountHeadName(blank:false, size:3..100,unique:true);
    }

   static  mapping = {
       statusDate(sqlType: 'date');
       headCreatedDate(sqlType: 'date');


   }


    public static void initialize(){
        def insertQuery=[
                ["Assets","asst",null,"101000",AccountType.get(1),'1',new Date(),true,0.00,null,null,User.get(1),new Date()],
                ["Income","inc",null,"102000",AccountType.get(1),'1',new Date(),true,0.00,null,null,User.get(1),new Date()],
                ["Expance","exp",null,"103000",AccountType.get(2),'1',new Date(),true,0.00,null,null,User.get(1),new Date()] ,
                ["Liabilities","lbts",null,"104000",AccountType.get(2),'1',new Date(),true,0.00,null,null,User.get(1),new Date()]
        ]

        insertQuery.each {
            AccountHead accountHead = null;
            try{
                accountHead = new AccountHead(accountHeadName: it[0], headShortName: it[1],accountParentHead: it[2],accountHeadCode: it[3],accountType: it[4],accountStatus: it[5],statusDate: it[6],isPosted: it[7],openingBalance: it[8],module: it[9],branch: it[10],user: it[11],headCreatedDate: it[12]);
                accountHead.save(flush:true);
            } catch(Exception e){
                e.printStackTrace();
            }

        }

    }
}
